<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="../layui/layui.js" type="text/javascript"></script>
		<script src="../js/formSelects-v4.js" type="text/javascript" charset="utf-8"></script>
		<link href="../layui/css/layui.css" rel="stylesheet" />
	</head>
	<body>
		
		<div class="layui-container" style="margin: 10px 0px; ">
			<form class="layui-form layui-form-pane">
				<div class="layui-form-item"> 
					<label class="layui-form-label">公告标题</label>
					<div class="layui-input-block">
						<input type="text" name="title" lay-verify="required|title" class="layui-input" placeholder="通知的标题，中文-必填" autocomplete="off">
					</div>	
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">截止时间</label>
						<div class="layui-input-inline" style="width: 250px;">
							<input type="text" id="validDate" lay-verify="required" name="validDate" class="layui-input" 
								placeholder="选择截止时间-必填" autocomplete="off">
						</div>	
					</div>
					
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">接收门户</label>
						<div class="layui-input-inline" style="width: 250px;">
							<input type="radio" lay-filter="mh" name="mh" title="所有门户" value="0" checked/>
							<input type="radio" lay-filter="mh" name="mh" title="指定门户" value="1"/>
						</div>	
						<div class="layui-input-inline" id="selectDiv" style="width: 300px;display: none;">
							<input type="hidden" name="acceptRole" id="acceptRole" value="all" />
							<select name="acceptRoles" id="acceptRoles" xm-select="select1">
								<option value="" title="请选择门户"></option>
								<option value="1">学校门户</option>
								<option value="2">专家门户</option>
								<option value="3">网站门户</option> 
							</select>
						</div>	
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">公告内容</label>
					<div class="layui-input-block">
						<textarea class="layui-textarea" id="content" name="content"></textarea>
					</div>	
				</div>
				<div class="layui-form-item" style="display: none;">
					<div class="layui-input-block">
						<a class="layui-btn" lay-submit="" lay-filter="submitBtn" id="submitBtn">提交</a>
						<a class="layui-btn" lay-submit="" lay-filter="contributionBtn" id="contributionBtn">草稿</a>
					</div>	
				</div>
			</form>
		</div>		
		<script>
			var $;
			layui.use(['form','laydate','layedit','jquery','layer'],function(){
				var form = layui.form,
				laydate = layui.laydate,
				layedit = layui.layedit,layer = layui.layer;
				$ = layui.jquery;
				var formSelects = layui.formSelects;
				
				form.on('radio(mh)',function(data){
					var value = data.value;
					if(value == 0){
						$('#selectDiv').hide();
						$('#acceptRole').val('all');
					}else{
						$('#selectDiv').show();
						$('#acceptRole').val("");
					}
				})
				
				form.verify({
					title:[/^[\u4e00-\u9fa5]{1,}$/,'请输入中文标题']
				});
				
				
				//获取当前系统时间 
				var date = new Date();
				var nowDate = (date.getFullYear())+"-"
				+(date.getMonth()+1)+"-"+(date.getDate());
				
				//时间初始化
				laydate.render({ 
					elem:'#validDate',
					min:nowDate
				})
				
				//初始化富文本
				var index = layedit.build('content',{
					tool:['underline','strong','left','right','center','face'],
					height:350,
					//uploadImage:{url:'',type:'post'}
				})
				var active = {
					insertOrUpdate:function(status){
						//获取编辑器的内容
						var content = layedit.getContent(index);
						var dataForm = data.field;
						//把内容存入属性
						dataForm.content = content;
						dataForm.status = status;
						/*$.ajax({
							type:'post',
							url:'${ssm}/notice/nc/insertOrUpdate',
							data:dataForm,
							dataType:'json',
							success:function(result){
								top.layer.msg(result.msg); 
								layer.closeAll();
							}
						})*/
					}
				}
				
				form.on('submit(submitBtn)',function(data){
					insertOrUpdate(1);
				})
				form.on('submit(contributionBtn)',function(data){
					insertOrUpdate(0);
				})
			});
			
			function btnSubmit(){
				$('#submitBtn').click();
			}
			function btnContribution(){
				$('#contributionBtn').click();
			}
		</script>
	</body>
</html>
